<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Amaze UI Admin index Examples</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/png" href="/static/assets/img/login1.png">
    <link rel="apple-touch-icon-precomposed" href="/static/assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <link rel="stylesheet" href="/static/assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="/static/assets/css/amazeui.datatables.min.css" />
    <link rel="stylesheet" href="/static/assets/css/app.css">
    <script src="/static/assets/js/jquery.min.js"></script>
    <style>
        .am-dropdown-toggle{
            color: rgb(182, 182, 183);
            font-size: 0.8rem;
        }
        .am-dropdown-content{
            font-size: 0.8rem;
        }
        .Content{
            width: 10rem;
            display: inline-block;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
        }
        .Content1{
            width: 25rem;
            height: 2rem;
            display: inline-block;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
        }
        .pagination{
            margin: 0 auto;
            width: 600px;
            text-align: center;
        }
        .pagination>li{
            margin-right: 1rem;
            width: 3rem;
            height: 3rem;
            line-height: 3rem;
            background-color: rgba(127, 146, 145, 0.315);
            float: left;
        }
        .active{
            font-size: 2rem;
            background-color: aqua;
            color: rgb(87, 85, 85);
        }
        .am-selected-text{
            display: inline-block;
            font-size: 1.3rem;
            text-align: center;
            color: rgba(37, 52, 53, 0.771);
            border-bottom: 1px rgba(182, 179, 179, 0.156) solid;
        }
        .am-selected-content{
            width: 100px;
        }
        .am-selected-list-header{
            background-color: rgba(177, 146, 146, 0.526);
        }
        .am-btn-default{
            height: 3.5rem;
        }
    </style>
</head>

<body data-type="widgets">
    <script src="/static/assets/js/theme.js"></script>
    <div class="am-g tpl-g">
        <!-- 头部 -->
        <header>
            <!-- logo -->
            <div class="am-fl tpl-header-logo">
                <a href="javascript:;"><img src="/static/assets/img/log.png" alt="" style="height: 50px;width: 140px;"></a>
            </div>
            <!-- 右侧内容 -->
            <div class="tpl-header-fluid">
                <!-- 侧边切换 -->
                <div class="am-fl tpl-header-switch-button am-icon-list">
                    <span>

                </span>
                </div>
                <!-- 搜索 -->
                <div class="am-fl tpl-header-search">
                    <form class="tpl-header-search-form" action="javascript:;">
                        <button class="tpl-header-search-btn am-icon-search"></button>
                        <input class="tpl-header-search-box" type="text" placeholder="搜索内容...">
                    </form>
                </div>
                <!-- 其它功能-->
                <div class="am-fr tpl-header-navbar">
                    <ul>
                        <!-- 欢迎语 -->
                        <li class="am-text-sm tpl-header-navbar-welcome">
                            <a href="javascript:;">欢迎您回来,亲爱的 <span>{$Think.session.name.admName}</span> </a>
                        </li>

                        <!-- 新邮件 -->
                        <li class="am-dropdown tpl-dropdown" data-am-dropdown>
                            <a href="http://127.0.0.1:5500/index.html" target="_blank">
                                <i class="am-icon-book"></i>文章系统前台
                                <!-- <span class="am-badge am-badge-success am-radius item-feed-badge">文章</span> -->
                            </a>
                        </li>

                        <!-- 退出 -->
                        <li class="am-text-sm">
                            <a href="javascript:;">
                                <span class="am-icon-sign-out"></span> 退出
                            </a>
                        </li>
                    </ul>
                </div>
            </div>

        </header>
        <!-- 风格切换 -->
        <div class="tpl-skiner">
            <div class="tpl-skiner-toggle am-icon-cog">
            </div>
            <div class="tpl-skiner-content">
                <div class="tpl-skiner-content-title">
                    选择主题
                </div>
                <div class="tpl-skiner-content-bar">
                    <span class="skiner-color skiner-white" data-color="theme-white"></span>
                    <span class="skiner-color skiner-black" data-color="theme-black"></span>
                </div>
            </div>
        </div>
        <!-- 侧边导航栏 -->
        <div class="left-sidebar">
            <!-- 用户信息 -->
            <div class="tpl-sidebar-user-panel">
                <div class="tpl-user-panel-slide-toggleable" style="text-align: center;">
                    <div class="tpl-user-panel-profile-picture" style="margin: 0 auto">
                        <img id="image" src="/static/uploads/{$Think.session.name.admAvatar}" alt="">
                    </div>
                    <span class="user-panel-logged-in-text">
                        <i class="am-icon-circle-o am-text-success tpl-user-panel-status-icon"></i>
                        {$Think.session.name.admName}
                    </span>
                    <a href="javascript:;" class="tpl-user-panel-action-link">
                        <span class="am-icon-black-tie"></span>
                        <li class="am-dropdown" data-am-dropdown>
                            <a class="am-dropdown-toggle" data-am-dropdown-toggle href="javascript:;">
                                {$Think.session.name.admAuthor} <span class="am-icon-caret-down"></span>
                            </a>
                            <ul class="am-dropdown-content">
                              <li class="am-dropdown-header">操作</li>
                              <li><a id="doc-prompt-toggle"><span class="am-icon-key"></span> 修改密码</a></li>
                              <li><a href="javascript:;" id="upload"><span class="am-icon-slideshare"></span> 更换头像</a></li>
                              <li class="am-divider"></li>
                              <li><a href="http://cms.com:8081/admin/admin/admOut?id={$Think.session.name.admID}"><span class="am-icon-sign-out"></span> 退出登录 </a></li>
                            </ul>
                        </li>
                    </a>
                </div>
            </div>

            <div style="display: none;">
                    <input id="file" type="file" name="image" onchange="uploadFile()">
            </div>
            <script>
                $("#upload").click(function(){
                    $("#file").click()
                })
                function uploadFile() {
                    var myform = new FormData();
                    // var id = {$Think.session.name.admID};
                    myform.append('image',$('#file')[0].files[0]);
                    $.ajax({
                        url: "http://cms.com:8081/admin/admin/admPhotoUp?id="+"{$Think.session.name.admID}",
                        type: "POST",
                        data: myform,
                        contentType: false,
                        processData: false,
                        success: function (data) {
                            $("#image").attr("src",'/static/uploads/'+JSON.parse(data))
                            console.log($("#image"))
                            $("#alert").css('display','block')
                            setTimeout(()=>{$("#alert").css('display','none')},4000)
                            console.log(data);
                        },
                        error:function(data){
                            console.log(data)
                        }
                    });
                }
            </script>
            <div class="am-alert am-alert-success" data-am-alert style="display: none; " id="alert">
                <button type="button" class="am-close">&times;</button>
                <p>没什么可给你，但求凭这阙歌。谢谢你风雨里，都不退愿陪着我。更改成功！</p>
            </div>
    

            <!-- 菜单 -->
            <ul class="sidebar-nav">
                <li class="sidebar-nav-heading">CMS<span class="sidebar-nav-heading-info"> 内容管理系统</span></li>
                <li class="sidebar-nav-link">
                    <a href="http://cms.com:8081/admin/admin/showHome">
                        <i class="am-icon-home sidebar-nav-link-logo"></i> 首页
                    </a>
                </li>
                {if $Think.session.name.admAuthor != '超级管理员'}
                <li class="sidebar-nav-link" style="pointer-events: none;">
                    <a href="#">
                        <i class="am-icon-user-secret sidebar-nav-link-logo"></i>
                         管理员列表
                        <i class="am-icon-warning sidebar-nav-link-logo" style="color: red;"></i>
                    </a>
                </li>
                {else}
                    <li class="sidebar-nav-link">
                        <li class="sidebar-nav-link">
                            <a href="http://cms.com:8081/admin/admin/showCalendar">
                                <i class="am-icon-user-secret sidebar-nav-link-logo"></i> 管理员列表
                            </a>
                        </li>
                    </li>
                {/if}
                <li class="sidebar-nav-link">
                    <a href="http://cms.com:8081/admin/admin/showTables">
                        <i class="am-icon-user sidebar-nav-link-logo"></i> 用户列表
                    </a>
                </li>

                <!-- 文章管理 -->
                <li class="sidebar-nav-link">
                    <a href="javascript:;" class="sidebar-nav-sub-title">
                        <i class="am-icon-book sidebar-nav-link-logo"></i> 文章管理
                        <span class="am-icon-chevron-down am-fr am-margin-right-sm sidebar-nav-sub-ico"></span>
                    </a>
                    <ul class="sidebar-nav sidebar-nav-sub" style="display: block;">
                        <li class="sidebar-nav-link">
                            <a href="http://cms.com:8081/admin/admin/showTableList">
                                <span class="am-icon-gg sidebar-nav-link-logo"></span> 分类管理
                            </a>
                        </li>

                        <li class="sidebar-nav-link">
                            <a href="http://cms.com:8081/admin/admin/showTableListImg" class="active">
                                <span class="am-icon-gg sidebar-nav-link-logo"></span> 文章列表
                            </a>
                        </li>
                        <li class="sidebar-nav-link">
                            <a href="http://cms.com:8081/admin/admin/showArtDown">
                                <i class="am-icon-gg sidebar-nav-link-logo"></i> 待审文章
                                <span class="am-badge am-badge-secondary sidebar-nav-link-logo-ico am-round am-fr am-margin-right-sm"></span></span>
                            </a>
                        </li>
                        <li class="sidebar-nav-link">
                            <a href="http://cms.com:8081/admin/admin/showFour">
                                <i class="am-icon-gg sidebar-nav-link-logo"></i> 上传文章
                            </a>
                        </li>
                    </ul>
                </li>

                <!-- 评论管理 -->
                <li class="sidebar-nav-link">
                    <a href="javascript:;" class="sidebar-nav-sub-title">
                        <i class="am-icon-commenting sidebar-nav-link-logo"></i> 评论管理
                        <span class="am-icon-chevron-up am-fr am-margin-right-sm sidebar-nav-sub-ico"></span>
                    </a>
                    <ul class="sidebar-nav sidebar-nav-sub">
                        <li class="sidebar-nav-link">
                            <a href="http://cms.com:8081/admin/admin/showForm">
                                <span class="am-icon-gg sidebar-nav-link-logo"></span> 音频列表
                            </a>
                        </li>

                        <li class="sidebar-nav-link">
                            <a href="http://cms.com:8081/admin/admin/showChart">
                                <span class="am-icon-gg sidebar-nav-link-logo"></span> 评论列表
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="sidebar-nav-link">
                    <a href="http://cms.com:8081/admin/admin/showSignUp">
                        <i class="am-icon-keyboard-o sidebar-nav-link-logo"></i> 注册
                        <!-- <span class="am-badge am-badge-secondary sidebar-nav-link-logo-ico am-round am-fr am-margin-right-sm">6</span> -->
                    </a>
                </li>
                <li class="sidebar-nav-link">
                    <a href="http://cms.com:8081/admin/admin/showLogin">
                        <i class="am-icon-key sidebar-nav-link-logo"></i> 登录
                    </a>
                </li>

            </ul>
        </div>



        <!-- 内容区域 -->
        <div class="tpl-content-wrapper">
            <div class="row-content am-cf">
                <div class="row">
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <div class="widget am-cf">
                            <div class="widget-head am-cf">
                                <div class="widget-title  am-cf">文章列表</div>


                            </div>
                            <div class="widget-body  am-fr">

                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                                    <div class="am-form-group">
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <button type="button" class="am-btn am-btn-default am-btn-success"><span class="am-icon-plus"></span> 新增</button>
                                                <button type="button" class="am-btn am-btn-default am-btn-secondary"><span class="am-icon-save"></span> 保存</button>
                                                <button type="button" class="am-btn am-btn-default am-btn-warning"><span class="am-icon-archive"></span> 审核</button>
                                                <button type="button" class="am-btn am-btn-default am-btn-danger"><span class="am-icon-trash-o"></span> 删除</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                                    <div class="am-form-group tpl-table-list-select">
                                        <select data-am-selected="{maxHeight: 300}" id="select">
                                            <optgroup>
                                                <option value="0">点击选择</option>
                                            </optgroup>
                                            {foreach $res as $v}
                                            <optgroup label="{$v.typName}">
                                                {foreach $v.res as $val}
                                                    <option value="{$val.typName}">{$val.typName}</option>
                                                {/foreach}
                                            </optgroup>
                                            {/foreach}
                                        </select>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                        <input type="text" class="am-form-field " id="input" value="0">
                                        <span class="am-input-group-btn">
                                            <button onclick="search()" class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" type="button"></button>
                                        </span>
                                    </div>
                                </div>

                                <div class="am-u-sm-12">
                                    <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
                                        <thead>
                                            <tr>
                                                <th class="am-text-center">ID</th>
                                                <th class="am-text-center">类型</th>
                                                <th class="am-text-center">作者</th>
                                                <th class="am-text-center">标题</th>
                                                <th class="am-text-center">内容</th>
                                                <th class="am-text-center">阅读量</th>
                                                <th class="am-text-center">评论量</th>
                                                <th class="am-text-center">点赞量</th>
                                                <th class="am-text-center">收藏量</th>
                                                <th class="am-text-center">推荐量</th>
                                                <th class="am-text-center">操作</th>
                                            </tr>
                                        </thead>
                                        <tbody id="search">
                                            {foreach $data as $val}
                                            <tr class="gradeX">
                                                <td class="am-text-center">{$val.artID}</td>
                                                <td class="am-text-center">{$val.articleType.0.typName}</td>
                                                <td class="am-text-center">{$val.artAuthor}</td>
                                                <td class="am-text-center"><div class="Content">{$val.artTitle}</div></td>
                                                <td class="am-text-center"><div class="Content1">{$val.artContent}</div></td>
                                                <td class="am-text-center">{$val.readNum}</td>
                                                <td class="am-text-center">{$val.comtNum}</td>
                                                <td class="am-text-center">{$val.praNum}</td>
                                                <td class="am-text-center">{$val.colNum}</td>
                                                <td class="am-text-center">{$val.pushNum}</td>
                                                <td class="am-text-center">
                                                    <div class="tpl-table-black-operation">
                                                        <a href="javascript:;" onclick="Takedown('{$val.artID}')">
                                                            <i class="am-icon-pencil"></i> 下架
                                                        </a>
                                                        <a href="javascript:;" onclick="artDel('{$val.artID}')" class="tpl-table-black-operation-del">
                                                            <i class="am-icon-trash"></i> 删除
                                                        </a>
                                                    </div>
                                                </td>
                                            </tr>
                                            {/foreach}
                                            <!-- more data -->
                                        </tbody>
                                    </table>
                                </div>
                                <div class="am-u-lg-12 am-cf">

                                    <div class="am-fr" id="page">
                                        {$page|raw}
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 修改密码 -->
    <div class="am-modal am-modal-prompt" tabindex="-1" id="my-prompt">
        <div class="am-modal-dialog">
          <div class="am-modal-hd">文字管理系统</div>
          <div class="am-modal-bd">
            <input type="password" class="am-modal-prompt-input" id="old" name="oldAdmPass" placeholder="请输入旧密码(至少六位数)" style="text-align: center;">
            <input type="password" class="am-modal-prompt-input" id="news" name="admPass" placeholder="请输入新密码(至少六位数)" style="text-align: center;">
          </div>
          <div class="am-modal-footer">
            <span class="am-modal-btn" data-am-modal-cancel>取消</span>
            <span class="am-modal-btn" data-am-modal-confirm>提交</span>
          </div>
        </div>
    </div> 
    <button
        id="show"
        type="button"
        class="am-btn am-btn-primary"
        data-am-modal="{target: '#my-alert'}" style="display: none;">
        Alert
    </button>
    <div class="am-modal am-modal-alert" tabindex="-1" id="my-alert">
        <div class="am-modal-dialog">
          <div class="am-modal-hd">文字管理系统</div>
          <div class="am-modal-bd">
           
          </div>
          <div class="am-modal-footer">
            <span class="am-modal-btn" onclick="shua()">确定</span>
          </div>
        </div>
    </div>
    <div class="am-modal am-modal-confirm" tabindex="-1" id="my-confirm">
        <div class="am-modal-dialog">
          <div class="am-modal-bd" id="prompt">
            
          </div>
          <div class="am-modal-footer">
            <span class="am-modal-btn" data-am-modal-cancel>取消</span>
            <span class="am-modal-btn" data-am-modal-confirm>确定</span>
          </div>
        </div>
    </div>
    <div class="am-modal am-modal-alert" tabindex="-1" id="my-alert2">
        <div class="am-modal-dialog">
          <div class="am-modal-bd" id="prompt2">
            
          </div>
          <div class="am-modal-footer">
            <span class="am-modal-btn" data-am-modal-confirm>确定</span>
          </div>
        </div>
    </div> 
    <div class="am-modal am-modal-prompt" tabindex="-1" id="my-prompt-down">
        <div class="am-modal-dialog">
          <div class="am-modal-hd">输入下架原因</div>
          <div class="am-modal-bd">
            <textarea type="text" class="am-modal-prompt-input" id="tarea" value=""></textarea>
          </div>
          <div class="am-modal-footer">
            <span class="am-modal-btn" data-am-modal-cancel>取消</span>
            <span class="am-modal-btn" data-am-modal-confirm>提交</span>
          </div>
        </div>
    </div>
    <script>
        function Takedown(e){
            $('#my-prompt-down').modal({
                onConfirm: function() {
                    var $textarea = $('#tarea').val()
                    $.ajax({
                        url: "http://cms.com:8081/admin/admin/artDown",
                        type: "POST",
                        data:{
                            id:e,
                            text:$textarea
                        },
                        success: function (data) {
                            var res = JSON.parse(data)
                            if(res == 1){
                                $('#prompt2').text('下架成功')
                                $('#my-alert2').modal({
                                    onConfirm: function(){
                                        window.location.reload()
                                    }
                                })
                            }
                        }
                    });
                },
                onCancel: function() {
                }
            });
        }
        function artDel(e){
            $('#prompt').text('确定要删除这篇文章吗？')
            $('#my-confirm').modal({
                onConfirm: function(options) {
                    $.ajax({
                        url: "http://cms.com:8081/admin/admin/artDel",
                        type: "POST",
                        data:{
                            id:e
                        },
                        success: function (data) {
                            var res = JSON.parse(data)
                            if(res == 1){
                                $('#prompt2').text('删除成功')
                                $('#my-alert2').modal({
                                    onConfirm: function(){
                                        window.location.reload()
                                    }
                                })
                            }
                        }
                    });
                },
                onCancel: function() {
                }
            });
        }
        $(function() {
            $('#doc-prompt-toggle').on('click', function() {
                $('#my-prompt').modal({
                relatedTarget: this,
                onConfirm: function(e) {
                    let old = $("#old").val()
                    let news = $("#news").val()
                    if(old.length <6 || news.length <6){
                        alert('至少六位数字！');
                        return
                    }
                    console.log(old)
                    console.log(news)
                    $.ajax({
                        url: "http://cms.com:8081/admin/admin/admUpdatePass",
                        type: "POST",
                        data: {
                            old,
                            news,
                            id:'{$Think.session.name.admID}'
                        },
                        success: function (data) {
                            if(data == 0){
                                $("#show").click()
                                $(".am-modal-bd").text('旧密码错误！')
                            }
                            if(data == 1){
                                $("#show").click()
                                $(".am-modal-bd").text('修改成功！')
                            }
                        }
                    });
                },
                });
            });
            });
            function shua(){
                window.location.reload()
            }
        
        
    
        function search(){
            var value = $("#select").val()
            var input = $("#input").val()
            console.log(value)
            console.log(input)
            $.ajax({
                url: "http://cms.com:8081/admin/admin/searchType",
                type: "POST",
                data: {value,input},
                success: function (res) {
                    $("#search").empty()
                    $("#page").empty()
                    var data = JSON.parse(res)
                    console.log(data)
                    for(var i=0;i<data.length;i++){
                        var $td = '<tr class="gradeX">'+
                                        '<td class="am-text-center">'+data[i].artID+'</td>'+
                                        '<td class="am-text-center">'+data[i].articleType[0].typName+'</td>'+
                                        '<td class="am-text-center">'+data[i].artAuthor+'</td>'+
                                        '<td class="am-text-center"><div class="Content">'+data[i].artTitle+'</div></td>'+
                                        '<td class="am-text-center"><div class="Content1">'+data[i].artContent+'</td>'+
                                        '<td class="am-text-center">'+data[i].readNum+'</div></td>'+
                                        '<td class="am-text-center">'+data[i].comtNum+'</td>'+
                                        '<td class="am-text-center">'+data[i].praNum+'</td>'+
                                        '<td class="am-text-center">'+data[i].colNum+'</td>'+
                                        '<td class="am-text-center">'+data[i].pushNum+'</td>'+
                                        '<td class="am-text-center">'+
                                            '<div class="tpl-table-black-operation">'+
                                                '<a href="javascript:;" onclick="Takedown('+data[i].artID+')">'+
                                                    '<i class="am-icon-pencil"></i> 下架'+
                                                '</a>'+
                                                '<a href="javascript:;" class="tpl-table-black-operation-del" onclick="artDel('+data[i].artID+')">'+
                                                    '<i class="am-icon-trash"></i> 删除'+
                                                '</a>'+
                                            '</div>'+
                                        '</td>'
                                    '</tr>'
                    $("#search").append($td)
                    }
                    
                }
            });
        }
        
    </script>
    <script src="/static/assets/js/amazeui.min.js"></script>
    <script src="/static/assets/js/app.js"></script>

</body>

</html>